﻿toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    var btn = $id("btn_" + fsid);
    var load = $id("load_" + fsid);
        
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    btn.style.display = display;
    load.style.display = display;
}

CV_New = function()
{
    var load = $id("load_CVNew");
    var btn = $id("btn_CVNew");
    if(confirm("save changes?"))
    {
        // di sini kirim data perubahannya
        var input = getCVData();
        //alert(input);
        if(input)
        {
            btn.style.display = "none";
            load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
            cbkCVNew_c.PerformCallback(input);
        }
        else
        {
            btn.style.display = "block";
            load.innerHTML = "";
        }
    }
}

getCVData = function()
{
    var inputs = $nm("txt");
    var output = "";
    var iEmptyValueCount = 0;
    
    var lovCompList = $id("lov_CV.CUSTOMERID");
    var lovCompListh = $id("lovh_CV.CUSTOMERID");
    var lovCP = $id("lov_CV.CPID");
    var lovCPh = $id("lovh_CV.CPID"); 
    if(lovCompListh.value == "")
    {
        iEmptyValueCount++;
    }  
    if(lovCPh.value == "")
    {
        iEmptyValueCount++;
    } 
    output += DELIMITER + lovCompList.id + NEWLINE + lovCompListh.value;
    output += DELIMITER + lovCP.id + NEWLINE + lovCPh.value;
    output += DELIMITER
    for( var i=0; i < inputs.length; i++ )
    {
        if( i > 0 )
        {
            output += DELIMITER;
        }
        
        var item = inputs[i];
        var lov = $id("lov_" + item.id);
        
        if( lov == null )
        {
            output += item.id + NEWLINE + item.value;
            if(item.value == "")
            {
                iEmptyValueCount++;
            }
        }
        else
        {
            var lovh = $id("lovh_" + item.id);
            output += lov.value + NEWLINE + lovh.value + NEWLINE + item.value;
                   
        }
    }
    
    var sxError = "";
    
    if( iEmptyValueCount > 0 )
    {
        sxError += "terdapat field isian yang belum diisi! ";
    }
    
    if( sxError != "" )
    {
        alert(sxError);
        return false;
    }
    
    return output;
}

cbkCVNew_c_CallbackComplete = function(e) {
    var selector = $id("CV.VISITSTATUS");
    if (selector.value == "PLANNED")
    {
        window.location = "CVList.aspx";
    }
    else if(selector.value == "DIRECT")
    {
        window.location = "CVReal.aspx?cvid=" + e.result;
    }
    //window.location = "UFTNew.aspx?eid=" + e.result;
}

SelectCompany = function()
{
    var lovhCompany = $id("lovh_CV.CUSTOMERID");
    var lovpContact = $id("lovp_CV.CPID");
    
    lovpContact.value = lovhCompany.value;
}
ShowSelectedContactData = function()
{
//do nothing
}